package listbyorder.access101_200.test162;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/13 13:18
 */
public class Solution1 {

    // N级别的时间复杂度
    public int findPeakElement(int[] nums) {
        if (nums.length == 1) return 0;
        if (nums[0] > nums[1]) return 0;
        int len = nums.length;
        if (nums[len - 1] > nums[len - 2]) return len - 1;
        int index = 1;
        while (index < nums.length - 1) {
            if (nums[index] > nums[index - 1] && nums[index] > nums[index + 1]) {
                return index;
            }
            index++;
        }
        throw new RuntimeException("参数输入有误");
    }
}
